// pages/myMedal/myMedal.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    httpApiImg: app.globalData.httpApiImg,
    imgUrl: app.globalData.imageUrl,
    userInfo: '',
    medalList:[
      { title: '勤能补拙', imgUrl:'pic_qingnengbuzhuo',checked:false},
      { title: '老司机', imgUrl: 'pic_laosiji', checked: false },
      { title: '人生赢家', imgUrl: 'pic_renshengyingjia', checked: false },
      { title: '精打细算', imgUrl: 'pic_jingdaxisuan', checked: false },
      { title: '活跃之星', imgUrl: 'pic_huoyuezhixing', checked: false },
      { title: '社交达人', imgUrl: 'pic_shejiaodaren', checked: false },
      { title: '助人为乐', imgUrl: 'pic_zhurenweile', checked: false},
      { title: '人气之星', imgUrl: 'pic_renqizhixing', checked: false}]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: JSON.parse(wx.getStorageSync('userInfo'))
    })
    this.getMedal('personalCenter/isContinuous', 0);
    this.getMedal('personalCenter/isOldDriver', 1);
    this.getMedal('personalCenter/isWinner', 2);
    this.getMedal('personalCenter/isCareful', 3);
    this.getMedal('personalCenter/isActiveStar', 4);
    this.getMedal('personalCenter/isSocial', 5);
    this.getMedal('personalCenter/isHelpful', 6); 
    this.getMedal('personalCenter/isPopulationStar', 7);
  },
  getMedal:function(url,index){
    var that=this;
    wx.request({
      url: app.globalData.httpApiCar + url, //仅为示例，并非真实的接口地址
      data: {
        userId: this.data.userInfo.id
      },
      success: function (res) {
        if (res.data.success) {
          that.setData({
            ['medalList[' + index +'].checked']:res.data.data
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})